<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //  求字符串数组中每一项的长度
    var arr = ['44444444444444', '555553dg', '3gtr', '8'];
    var new_arr = [];
    for (var i in arr) {
      new_arr[new_arr.length] = arr[i].length;
    }
    console.log(new_arr);
    // 将字符串数组用|或其他符号分割
    var arr1 = ['96', '7', '2'];
    var link = "|";
    var arr2 = arr1[0];
    for (var i = 1; i < arr1.length; i++) {
      arr2 += link + arr1[i];
    }
    console.log(arr2);
    // 有一个从小到大排好序的数组。现输入一个数，要求按原来的规律将它插入数组中
    var arr = [1, 20, 40, 60, 80, 100];
    var num = parseInt(prompt('请输入一个数'));
    arr.unshift(num);
    for (var i = 0; i < arr.length - 1; i++) {
      for (var j = 0; j < arr.length - 1 - i; j++) {
        if (arr[j] > arr[j + 1]) {
          [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
        }
      }
    }
    console.log(arr);
  // 猴子选大王
    var total = prompt("请输入猴子个数：");
        var kick = prompt("请输入踢出第几只猴子：");
        var monkey = [];
        for(var i=0;i<total;i++ ){
            monkey.push(i); 
        }
        i=0;
        while(monkey.length>1){
            i++;
            var head = monkey.shift();
            if(i%kick!=0){
                monkey.push(head);
            }
        }
        console.log(("第"+(monkey[0]+1)+"只是猴王"))
  </script>
</body>

</html>